package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.Email;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by Student on 21.11.2014.
 */
public class EmailService {

    private Queue queue;
    private volatile boolean isClosed = false;
    private Thread mailThread;

    public EmailService() {
        this.queue = new Queue( new LinkedList<Email>());

        mailThread = new Thread(new MailsThread(queue));
        mailThread.start();
    }


    public void sendNotificationEmail(Client client) {
        Email email = new Email(client,client.getName());
        queue.add(email);
    }

    public void close() {

        isClosed = true;
        if (mailThread != null)
            mailThread.interrupt();
    }
}
